package others;

import utils.PropertiesUtils;

import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;

/**
 * @version V1.0
 * @Title: 组件颜色处理类
 * @Package
 * @Description: 根据配置文统一处理组件的颜色
 * @author: GaleBlade
 * @date:
 */
public class ItemColorChange {

    public static PropertiesUtils settings = new PropertiesUtils("SETTINGS.properties");

    public static BufferedImage change(BufferedImage bImage) {

        //获取图片的长宽高
        int width = bImage.getWidth();
        int height = bImage.getHeight();

        int r = Integer.parseInt(settings.get("font.r"));
        int g = Integer.parseInt(settings.get("font.g"));
        int b = Integer.parseInt(settings.get("font.b"));

        //遍历图片的所有像素点，并对各个像素点进行判断，是否修改
        WritableRaster raster = bImage.getRaster();

        for (int xx = 0; xx < width; xx++) {
            for (int yy = 0; yy < height; yy++) {
                int[] pixels = raster.getPixel(xx, yy, (int[]) null);
                pixels[0] = r;
                pixels[1] = g;
                pixels[2] = b;
                raster.setPixel(xx, yy, pixels);
            }
        }
        return bImage;
    }

    public static BufferedImage hover(BufferedImage bImage) {

        //获取图片的长宽高
        int width = bImage.getWidth();
        int height = bImage.getHeight();

        int r = 255;
        int g = 255;
        int b = 255;

        //遍历图片的所有像素点，并对各个像素点进行判断，是否修改
        WritableRaster raster = bImage.getRaster();

        for (int xx = 0; xx < width; xx++) {
            for (int yy = 0; yy < height; yy++) {
                int[] pixels = raster.getPixel(xx, yy, (int[]) null);
                pixels[0] = r;
                pixels[1] = g;
                pixels[2] = b;
                raster.setPixel(xx, yy, pixels);
            }
        }
        return bImage;
    }

    public static BufferedImage hoverForCombo(BufferedImage bImage) {

        //获取图片的长宽高
        int width = bImage.getWidth();
        int height = bImage.getHeight();

//        int r = 255;
//        int g = 255;
//        int b = 255;

        int r = Integer.parseInt(settings.get("font.r"));
        int g = Integer.parseInt(settings.get("font.g"));
        int b = Integer.parseInt(settings.get("font.b"));

        //遍历图片的所有像素点，并对各个像素点进行判断，是否修改
        WritableRaster raster = bImage.getRaster();

        for (int xx = 0; xx < width; xx++) {
            for (int yy = 0; yy < height; yy++) {
                int[] pixels = raster.getPixel(xx, yy, (int[]) null);
                pixels[0] = r;
                pixels[1] = g;
                pixels[2] = b;
                if (r!=0 && g!=0 && b!=0){
                    raster.setPixel(xx, yy, pixels);
                }
            }
        }
        return bImage;
    }

}
